# coding=utf-8
from pages.aboutpage import AboutPage
from pages.addpage import AddPage
from pages.bulkdelete import TruncatePage
from pages.guestbook import GuestBook, ListGuestBookPage
from pages.listtopicpage import ListTopicPage
from pages.postpage import PostPage
from pages.remove_tid import RemoveTidPage
from pages.showpage import Show
from pages.tmp_page import TmpPage
import webapp2


class MainPage(webapp2.RequestHandler):
    def get(self):
        try:
            self.response.headers['Content-Type'] = 'text/html;charset=utf-8'
            self.response.write('<html><body>')
            self.response.write('welcome to homepage [%s]</br>' % (str(__name__)))
            self.response.write('GFW 你大爺的遜！ ')
            self.response.write('<a href="http://www.chinagfw.org" target="_blank">Anti-GFW</a></br>')
            self.response.write('<a href="/about" target="_blank">关于</a></br>')
            self.response.write('<a href="/post" target="_blank">发帖</a></br>')
            self.response.write('<a href="/listtopic" target="_blank">看贴</a></br>')
            self.response.write('<a href="/tmp" target="_blank">tmp</a></br>')
            self.response.write('<a href="/listbook" target="_blank">guestbook</a></br>')
            self.response.write('<a href="/truncate" target="_blank">truncate all</a></br>')
            self.response.write('<a href="add?first=50000000&second=888" target="_blank">做加法</a>')
            self.response.write('''
            <form action="/show" method="post">
                                姓名<input type="text" name="txtname"></br>
                                密码<input type="password" name="txtpasswd"></br>
                <input type="submit" text="ok">
                <input type="reset" text="cancel">
            </form>
            ''')
            self.response.write('</body></html>')
        except Exception as e:
            self.response.write('error ->' + e)


def launchWSGI(controller):
    return webapp2.WSGIApplication(controller, debug=True)

if __name__ == '__main__':
    print 'in main'
else:  # __name__ is the name of the file (i.e helloworld)
    list_controller = [
       ('/', MainPage), ('/add', AddPage),
       ('/about', AboutPage), ('/show', Show),('/post', PostPage),
       ('/listbook', ListGuestBookPage),('/sign', GuestBook),('/truncate',TruncatePage),
       ('/listtopic',ListTopicPage),('/tmp',TmpPage),('/remove',RemoveTidPage)
        ]
    app = launchWSGI(list_controller)
